package main

import (
	"context"
	"fmt"
	"github.com/coreos/etcd/clientv3"
	"time"
)

func main() {
	cli, err := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		fmt.Println(err)
	}
	kv := clientv3.NewKV(cli)
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	getResp, err := kv.Get(ctx, "username")
	defer cancel()
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(string(getResp.Kvs[0].Value)) // 如果没有key则Kvs为[]

}
